//
//  BaseCollectionReusableView.m
//  BasicProject
//
//  Created by 马军凯 on 2023/4/13.
//

#import "BaseCollectionReusableView.h"

@implementation BaseCollectionReusableView
//头
+ (instancetype)baseHeaderViewWith:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath {
    
    NSString *reuseIdString = NSStringFromClass(self);
    
    NSString *path = [[NSBundle mainBundle] pathForResource:reuseIdString ofType:@"nib"];
    if (path.length > 0) {
        UINib *nib = [UINib nibWithNibName:reuseIdString bundle:[NSBundle mainBundle]];
        [collectionView registerNib:nib forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdString];
        
    } else {
        [collectionView registerClass:NSClassFromString(reuseIdString) forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdString];
    }
    
    BaseCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdString forIndexPath:indexPath];
    
    return headView;
}
//尾
+ (instancetype)baseFooterViewWith:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath {
    NSString *reuseIdString = NSStringFromClass(self);
    
    NSString *path = [[NSBundle mainBundle] pathForResource:reuseIdString ofType:@"nib"];
    if (path.length > 0) {
        UINib *nib = [UINib nibWithNibName:reuseIdString bundle:[NSBundle mainBundle]];
        [collectionView registerNib:nib forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:reuseIdString];
    } else {
        [collectionView registerClass:NSClassFromString(reuseIdString) forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:reuseIdString];
    }
    
    BaseCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:reuseIdString forIndexPath:indexPath];
    
    return headView;
}


@end
